home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 735 / powervisor / docs / convertguide2doc.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  2KB  |  76 lines

  1. /* Use this utility to convert an AmigaGuide document to a normal
  2.    document file without all the @Node, @EndNode, ... commands
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. int main (int argc, char *argv[])
  9. {
  10.     FILE *fp;
  11.     int state;
  12.     char *buf,*buf2,*p,*p2;
  13.  
  14.     buf = malloc (4096);
  15.     buf2 = malloc (4096);
  16.     if (buf && buf2 && argc > 1)
  17.         {
  18.             if (fp = fopen (argv[1],"r"))
  19.                 {
  20.                     while (fgets (buf,4093,fp))
  21.                         {
  22.                             buf[strlen (buf)-1] = 0;
  23.                             if (!strnicmp (buf,"@Node",5))
  24.                                 {
  25.                                     puts ("----------------------------------------------------------------------------------");
  26.                                     puts (buf+6);
  27.                                     puts ("----------------------------------------------------------------------------------");
  28.                                 }
  29.                             else if (!strnicmp (buf,"@Database",9))
  30.                                 ;
  31.                             else if (!strnicmp (buf,"@master",7))
  32.                                 ;
  33.                             else if (!strnicmp (buf,"@EndNode",8))
  34.                                 ;
  35.                             else if (p = strstr (buf,"@{"))
  36.                                 {
  37.                                     state = 0;
  38.                                     p2 = buf2;
  39.                                     p = buf;
  40.                                     while (*p)
  41.                                         {
  42.                                             switch (state)
  43.                                                 {
  44.                                                     case 0 :    /* Initial state */
  45.                                                         if (*p == '@' && *(p+1) == '{') { p++; state = 1; }
  46.                                                         else *p2++ = *p;
  47.                                                         break;
  48.                                                     case 1 :    /* Waiting for first double quote */
  49.                                                         if (*p == '"' && *(p+1) == ' ') { *p2++ = '\''; p++; state = 2; }
  50.                                                         else if (*p == '"') { *p2++ = '\''; state = 2; }
  51.                                                         break;
  52.                                                     case 2 :    /* Waiting for second double quote */
  53.                                                         if (*p == ' ' && *(p+1) == '"') { *p2++ = '\''; p++; state = 3; }
  54.                                                         else if (*p == '"') { *p2++ = '\''; state = 3; }
  55.                                                         else *p2++ = *p;
  56.                                                         break;
  57.                                                     case 3 :    /* Waiting for '}' */
  58.                                                         if (*p == '}') state = 0;
  59.                                                         break;
  60.                                                 }
  61.                                             p++;
  62.                                         }
  63.                                     *p2 = 0;
  64.                                     puts (buf2);
  65.                                 }
  66.                             else puts (buf);
  67.                         }
  68.                     fclose (fp);
  69.                 }
  70.             else printf ("Error opening file!\n");
  71.         }
  72.     else printf ("Usage: ConvertGuide2Doc <filename>\n");
  73.     if (buf) free (buf);
  74.     if (buf2) free (buf2);
  75. }
  76.